package com.ruoyi.energize.util;

import com.alibaba.fastjson2.JSONObject;
import com.ovopark.sdk.openplatform.GwInitRequestHandler;
import com.ovopark.sdk.openplatform.core.OvoParkHttpClient;

import java.time.LocalDateTime;

public class GetGenderData {
	static final String apigwUrl="https://cloudapi.ovopark.com/cloud.api";
	static final String _akey="75b0d3f61cdb8f04afcee68468c77b9a";//开放平台密匙
	static final String _asid="bfe8ea0e8ff39ad284df3e3d8c405ab8";//开放平台密钥
	/**
	 * 获取所有的门店列表接口
	 */
	public String getDepartments(){
		//初始化
		GwInitRequestHandler requestHandler = new GwInitRequestHandler();
		requestHandler.init();
		requestHandler.setApplicationKey(_akey);
		requestHandler.setApplicationSecret(_asid);

		//设置需要调用的方法
		requestHandler.setMethod("open.organize.departments.getDepartments");
		requestHandler.setGateUrl(apigwUrl);
		requestHandler.setParameter("_aid","DC-000228");//开放平台系统编号
		OvoParkHttpClient httpClient = new OvoParkHttpClient();
		httpClient.setHeaders("authenticator","D6C229D37FD6F33475D6BBF91E415A68C76407A3452573A9EEC401244E7EB19E306DBB90FD1C17149B90AB4B7810B1E7552A8336D8CE73D63E9D24C51675365B");//token
		//获取请求带参数的url
		String requestUrl = requestHandler.getRequestURL();
		//设置请求内容
		httpClient.setReqContent(requestUrl);
		if (httpClient.call()) {
			String resContent = httpClient.getResContent();
			return resContent;
		}else{
			return "";
		}
	}

	/**
	 * 多门店小时数据 （对应业务平台客流数据）-【兼容PC4,PC5,PC6,PC8】）
	 * 时间类型 1-时 2-天 3-周 4-月 5-季 6-年 趋势的时间纬度 默认是1
	 * @return
	 */
	public String getManyShopsPassengerIndicatorData(String ids,String startTime, String endTime,String timeType){
		//初始化
		GwInitRequestHandler requestHandler = new GwInitRequestHandler();
		requestHandler.init();
		requestHandler.setApplicationKey(_akey);
		requestHandler.setApplicationSecret(_asid);

		//设置需要调用的方法
		requestHandler.setMethod("open.passengerflow.getManyShopsPassengerIndicatorData");
		requestHandler.setGateUrl(apigwUrl);
		requestHandler.setParameter("_aid","DC-000228");//开放平台系统编号
		requestHandler.setParameter("id",ids);
		requestHandler.setParameter("startTime",startTime);
		requestHandler.setParameter("endTime",endTime);
		requestHandler.setParameter("timeType",timeType);
		OvoParkHttpClient httpClient = new OvoParkHttpClient();
		httpClient.setHeaders("authenticator","D6C229D37FD6F33475D6BBF91E415A68C76407A3452573A9EEC401244E7EB19E306DBB90FD1C17149B90AB4B7810B1E7552A8336D8CE73D63E9D24C51675365B");//token
		//获取请求带参数的url
		String requestUrl = requestHandler.getRequestURL();
		//设置请求内容
		httpClient.setReqContent(requestUrl);
		if (httpClient.call()) {
			String resContent = httpClient.getResContent();
			return resContent;
		}else{
			return "";
		}
	}

	public String getSyncYesterdayAgeAndGenderData(String startHourTime,String endHourTime){
		//初始化
		GwInitRequestHandler requestHandler = new GwInitRequestHandler();
		requestHandler.init();
		requestHandler.setApplicationKey(_akey);
		requestHandler.setApplicationSecret(_asid);

		//设置需要调用的方法
		requestHandler.setMethod("open.passengerflow.getAgeAndGenderDistribution");
		requestHandler.setGateUrl(apigwUrl);
		requestHandler.setParameter("_aid","DC-000228");//开放平台系统编号
		requestHandler.setParameter("id","S_225885");
		requestHandler.setParameter("stime",startHourTime);
		requestHandler.setParameter("etime",endHourTime);
		requestHandler.setParameter("isOnBusinessTime", String.valueOf(1));
		OvoParkHttpClient httpClient = new OvoParkHttpClient();
		httpClient.setHeaders("authenticator","D6C229D37FD6F33475D6BBF91E415A68C76407A3452573A9EEC401244E7EB19E306DBB90FD1C17149B90AB4B7810B1E7552A8336D8CE73D63E9D24C51675365B");//token
		//获取请求带参数的url
		String requestUrl = requestHandler.getRequestURL();
		//设置请求内容
		httpClient.setReqContent(requestUrl);
		if (httpClient.call()) {
			String resContent = httpClient.getResContent();
			return resContent;
		}else{
			return "";
		}
	}

}
